<template>
    <div>
        <a href='/'>返回首页</a>
        <h1>房号录入</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>门店</td>
                    <td>
                        <select v-model="info.RoomModelId">
                            <option value="">请选择</option>
                            <option v-for="a in lisr" :value="a.Id">{{ a.RoomName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="info.RoomTypeId">
                            <option value="">请选择</option>
                            <option v-for="a in fx" :value="a.Id">{{ a.FXName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房间号</td>
                    <td><input type="text" v-model="info.FJH"></td>
                </tr>

                <tr>
                    <td>房号状态</td>
                    <td><input type="radio" name="str" :value="true" v-model="info.NumberState">上架
                        <input type="radio" name="str" :value="false" v-model="info.NumberState">下架
                    </td>
                </tr>


                <tr>
                    <td></td>
                    <td><input type="button" value="录入" @click="ok"></td>
                </tr>

            </tbody>

        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    "RoomModelId": "",
    "RoomTypeId": "",
    "FJH": "",
    "NumberState": "",
})
let lisr: any = ref([]);
let fx: any = ref([]);
onMounted(() => {
    getMD();
    getFX();
})
const getFX = () => {
    axios({
        url: '/api/Num/ShowFX',
        method: 'get'
    })
        .then(res => {
            console.log(res);
            fx.value = res.data
        })
}

const getMD = () => {
    axios({
        url: '/api/Num/Show',
        method: 'get'
    })
        .then(res => {
            console.log(res);
            lisr.value = res.data
        })
}


const ok = () => {
    if (info.RoomModelId == "") {
        alert("门店类型不能为空")
        return;
    }
    if (info.RoomTypeId == "") {
        alert("房型类型不能为空")
        return;
    }
    if (info.FJH == "") {
        alert("房间号不能为空")
        return;
    }

    axios({
        url: '/api/Num/NumAdd',
        method: 'post',
        data: info
    })
        .then(res => {
            if (res.data == -1) {
                alert('房间号重复')
                return;
            }
            if (res.data > 0) {
                alert('录入成功')
                router.push('/numshow')
                return;
            }
            else {
                alert("录入失败")
                return;
            }

        }).catch(err => {
            console.log(err);

        })
}
</script>

<style scoped></style>